<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:73:"C:\wamp200\www\localxgw/application/common\view\default\form\addlist.html";i:1533868864;}*/ ?>
<table class="table table-bordered">
      <thead>
        <tr>
          <th>规格名称<span style="color:red;">(必填)</span></th>
          <th>价格1<span style="color:red;">(必填)</span></th>
          <th>价格2<span style="color:red;">(必填)</span></th>
          <th>价格3<span style="color:red;">(必填)</span></th>
          <th>价格4<span style="color:red;">(必填)</span></th>
          <!-- <th>重量（单位斤）</th> -->
          <!--<th>成本价格</th>-->
          <!-- <th>代理价格</th> -->
          <!--<th>打包价格</th>-->
          <th>市场价格<span style="color:red;">(必填)</span></th>
          <th>剩余库存</th>
          <th>限购(不限购：0)</th>
          <th></th>
        </tr>
      </thead>
      <tbody id="rulebox">

        <?php if(empty($value) || ($value instanceof \think\Collection && $value->isEmpty())): ?>
        <tr>
          <td><input type="text" name="rule_name[]" /></td>
          <td><input type="text" name="rule_price[]" /></td>
          <td><input type="text" name="rule_price2[]" /></td>
          <td><input type="text" name="rule_price3[]" /></td>
          <td><input type="text" name="rule_price4[]" /></td>
          <!-- <td><input type="text" name="weight[]" /></td> -->
          <!--<td><input type="text" name="cost_price[]" /></td>-->
          <!-- <td><input type="text" name="agent_price[]" /></td> -->
          <!--<td><input type="text" name="pack_price[]" /></td>-->
          <td><input type="text" name="market_price[]" /></td>
          <td><input type="text" name="stock[]" value='999' /></td>
          <td><input type="text" name="quota[]" value='0' /></td>
          <td><a href="javascript:void(0);" class="btn btn-success" data-dismiss="addrule" style="padding:5px;">添加规格</a></td>
        </tr>
        <?php else: if(is_array($value) || $value instanceof \think\Collection): $i = 0; $__LIST__ = $value;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
            <tr>
                <input type="hidden" name="rule_id[]" value="<?php echo $vo['id']; ?>"  />
            <td><input type="text" name="rule_name[]" value="<?php echo $vo['rule_name']; ?>" /></td>

            <td><input type="text" name="rule_price[]" value="<?php echo $vo['rule_price']; ?>" /></td>
              <td><input type="text" name="rule_price2[]"  value="<?php echo $vo['rule_price2']; ?>"/></td>
              <td><input type="text" name="rule_price3[]"  value="<?php echo $vo['rule_price3']; ?>"/></td>
              <td><input type="text" name="rule_price4[]"  value="<?php echo $vo['rule_price4']; ?>"/></td>
            <!-- <td><input type="text" name="weight[]" value="<?php echo $vo['weight']; ?>" /></td> -->
            <!--<td><input type="text" name="cost_price[]" value="<?php echo $vo['cost_price']; ?>" /></td>-->
            <!-- <td><input type="text" name="agent_price[]" value="<?php echo $vo['agent_price']; ?>" /></td> -->
            <!--<td><input type="text" name="pack_price[]" value="<?php echo $vo['pack_price']; ?>" /></td>-->
            <td><input type="text" name="market_price[]" value="<?php echo $vo['market_price']; ?>" /></td>
            <td><input type="text" name="stock[]" value="<?php echo $vo['stock']; ?>" /></td>
            <td><input type="text" name="quota[]" value="<?php echo $vo['quota']; ?>" /></td>
            <td>
              <?php if($i == '1'): ?>
                <a href="javascript:void(0);" class="btn btn-success" data-dismiss="addrule" style="padding:5px;">添加规格</a></td>
              <?php else: ?>
                <a href="javascript:void(0);" class="btn btn-danger" data-dismiss="removerule" style="padding:5px;">移除</a>
              <?php endif; ?>
            </tr>
          <?php endforeach; endif; else: echo "" ;endif; endif; ?>

      </tbody>
    </table>


    <script id="tpl" type="text/x-jquery-tmpl">
      <tr>
      <td><input type="text" name="rule_name[]" /></td>
          <td><input type="text" name="rule_price[]" /></td>
          <td><input type="text" name="rule_price2[]" /></td>
          <td><input type="text" name="rule_price3[]" /></td>
          <td><input type="text" name="rule_price4[]" /></td>
      <td><input type="text" name="market_price[]" /></td>

      <td><input type="text" name="stock[]" value='999' /></td>
      <td><input type="text" name="quota[]" value='0' /></td>
      <td><a href="javascript:void(0);" class="btn btn-danger" data-dismiss="removerule" style="padding:5px;">移除</a></td>
      </tr>
    </script>
    <script src="__PUBLIC__/js/jquery.tmpl.js" charset="utf-8"></script>
<script>
  $.template( 'tpl', $("#tpl"));
  $('[data-dismiss="addrule"]').click(function(){
    data = {'name':1};
    $.tmpl( 'tpl', data ).appendTo($("#rulebox"));
  })
  $(document).on('click', '[data-dismiss="removerule"]',function(){
    $(this).parents('tr').remove();
  })

  $('[name="rule_price2[]"]').blur(function(){
  var $tr = $(this).parents('tr'),
      val2 = $(this).val();

      var val = val2*0.9,
          val3 = val2*1.1,
          val4 = val2*1.2;
  $tr.find('[name="rule_price[]"]').val(val.toFixed(1))
  $tr.find('[name="rule_price3[]"]').val(val3.toFixed(1))
  $tr.find('[name="rule_price4[]"]').val(val4.toFixed(1))

  });

</script>
